package com.dynamictpm.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiStyle;

/**
 * Dynamic thread-pool print banner.
 */
@Slf4j
public class DynamicThreadPoolBannerHandler implements InitializingBean {



    private final String DYNAMIC_THREAD_POOL = " :: Dynamic ThreadPool Monitor:: ";

    private final String HIPPO4J_GITHUB = "Gitee::  https://gitee.com/ityml/dynamic-tpm";

    private final String HIPPO4J_SITE = "Site::  https://www.ityml.com";

    private final int STRAP_LINE_SIZE = 50;



    public DynamicThreadPoolBannerHandler() {

    }

    @Override
    public void afterPropertiesSet() {
        printBanner();
    }

    /**
     * Print banner.
     */
    private void printBanner() {
        String banner ="  _____                              _        _______ _____  __  __ \n" +
                " |  __ \\                            (_)      |__   __|  __ \\|  \\/  |\n" +
                " | |  | |_   _ _ __   __ _ _ __ ___  _  ___     | |  | |__) | \\  / |\n" +
                " | |  | | | | | '_ \\ / _` | '_ ` _ \\| |/ __|    | |  |  ___/| |\\/| |\n" +
                " | |__| | |_| | | | | (_| | | | | | | | (__     | |  | |    | |  | |\n" +
                " |_____/ \\__, |_| |_|\\__,_|_| |_| |_|_|\\___|    |_|  |_|    |_|  |_|\n" +
                "          __/ |                                                     \n" +
                "         |___/                                                      ";
        if (true) {
            String bannerVersion ="new--version";
            StringBuilder padding = new StringBuilder();
            while (padding.length() < STRAP_LINE_SIZE - (bannerVersion.length() + DYNAMIC_THREAD_POOL.length())) {
                padding.append(" ");
            }
            System.out.println(AnsiOutput.toString(banner, AnsiColor.GREEN, DYNAMIC_THREAD_POOL, AnsiColor.DEFAULT,
                    padding.toString(), AnsiStyle.FAINT, bannerVersion, "\n\n", HIPPO4J_GITHUB, "\n", HIPPO4J_SITE, "\n"));

        }
    }

    /**
     * Get version.
     *
     * @return hippo4j version
     */
    public String getVersion() {
        return "version";
    }
}
